<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<link rel="stylesheet" type="text/css" href="css/login.css" />
		<title>登录</title>
	</head>

	<body>
		<div class="container">
			<div class="imgBox">
				<img src="images/img-login.jpg" />
			</div>
			<div class="logoBox">
				<!-- <img src="images/logo.png" /> -->
			</div>
			<div class="tubiao">
				<img src="images/tubiao.png" />
			</div>
			<div class="loginBox">
				<div class="inputBox">
					<h1>账号</h1>
					<input type="text" id="username" />
				</div>
				<div class="inputBox">
					<h1>密码</h1>
					<input type="password" id="password" />
				</div>
				<div class="login">
					<a id="login">登录</a>
				</div>
				<!-- <a class="register" href="register.html">账号注册</a> -->
				<form action="http://211.149.143.58:9001/word/extra/login" method="post" id="jsForm" style="display: none;">
					<input placeholder="账号" name="username" /><br />
					<input placeholder="密码" name="password" /><br />
					<button id="btn">提交</button>
				</form>

			</div>
		</div>
		<script src="js/jquery-1.11.1.min.js"></script>
		<script src="js/common.js"></script>
		<script>
			$("#login").on('click', function() {
				login()
			})
			$("#password").keypress(function(event) {
				if (event.keyCode == 13) {
					login()
				}
			});

			function login() {
				var $username = $("#username").val();
				var $password = $("#password").val();
				var sendData = {
					username: $username,
					password: $password,
					// code: 1234
				};
				if ($username.length == 0 && $password.length == 0) {
					tool.tips("请填写账号和密码！")
				} else if ($username.length == 0) {
					tool.tips("请输入账号！")
				} else if ($password.length == 0) {
					tool.tips("请填写密码！")
				} else {
					/* // 异步请求1
					$.post(url, {
						username: $username,
						password: $password
					}, function(data) {
						console.log(data)
					}, "json") */
					//异步请求2
					$.ajax({
						url: url.basic + 'login',
						type: 'POST',
						// headers: {
						// 	"token": token //此处放置请求到的用户token
						// },
						dataType: 'json',
						contentType: "application/json",
						// async: true, //异步请求
						// cache: false,
						data: JSON.stringify(sendData),
						//执行成功的回调函数
						success: function(res) {
							if (res.code == 200) {
								window.localStorage.token = res.data.token;
								tool.tips(res.message)
								setTimeout(function() {
									window.location.href = "email.html";
								}, 800)
							} else {
								tool.tips(res.message)
							}
						},
						//执行失败或错误的回调函数
						error: function(res) {
							console.log(res)
							tool.tips("登录失败，暂不能使用该服务！")
						}
					});
				}
			}
		</script>
	</body>
</html>
